package com.css.fxfzypg.modules.baseData.verify;

import cn.afterturn.easypoi.excel.entity.result.ExcelVerifyHandlerResult;
import cn.afterturn.easypoi.handler.inter.IExcelVerifyHandler;
import com.css.fxfzypg.modules.baseData.entity.HisPrEntity;
import com.css.fxfzypg.util.PlatformObjectUtils;
import org.springframework.stereotype.Component;

import java.math.BigDecimal;

@Component
public class HisPrExcelVerifyHandler implements IExcelVerifyHandler<HisPrEntity> {
    @Override
    public ExcelVerifyHandlerResult verifyHandler(HisPrEntity hisPrEntity) {
        ExcelVerifyHandlerResult result = new ExcelVerifyHandlerResult(true);
        StringBuilder message = new StringBuilder("");

        if (PlatformObjectUtils.isEmpty(hisPrEntity.getDhpYear())) {
            result.setSuccess(false);
            message.append("年份不能为空！");
        }

        if (PlatformObjectUtils.isEmpty(hisPrEntity.getDhpTaskName())) {
            result.setSuccess(false);
            message.append("任务名称不能为空！");
        }

        if (PlatformObjectUtils.isEmpty(hisPrEntity.getDhpEarthquakeNum())) {
            result.setSuccess(false);
            message.append("设定地震序号不能为空！");
        }

        BigDecimal dhpEpicenterLongitude = hisPrEntity.getDhpEpicenterLongitude();
        if (PlatformObjectUtils.isEmpty(dhpEpicenterLongitude)) {
            result.setSuccess(false);
            message.append("经度不能为空！");
        }else{
            boolean res = dhpEpicenterLongitude.scale() > 2 ? false : true;
            if(!res){
                result.setSuccess(false);
                message.append("经度需保留两位小数！");
            }
        }

        BigDecimal dhpEpicenterLatitude = hisPrEntity.getDhpEpicenterLatitude();
        if (PlatformObjectUtils.isEmpty(dhpEpicenterLatitude)) {
            result.setSuccess(false);
            message.append("纬度不能为空！");
        }else{
            boolean res = dhpEpicenterLatitude.scale() > 2 ? false : true;
            if(!res) {
                result.setSuccess(false);
                message.append("纬度需保留两位小数！");
            }
        }

        if (PlatformObjectUtils.isEmpty(hisPrEntity.getDhpLocation())) {
            result.setSuccess(false);
            message.append("宏观位置不能为空！");
        }

        BigDecimal dhpMagnitude = hisPrEntity.getDhpMagnitude();
        if (PlatformObjectUtils.isEmpty(dhpMagnitude)) {
            result.setSuccess(false);
            message.append("震级不能为空！");
        }else{
            boolean res = dhpMagnitude.scale() > 1 ? false : true;
            if(!res){
                result.setSuccess(false);
                message.append("震级需保留一位小数！");
            }
        }
        result.setMsg(message.toString());
        return result;
    }

}
